package com.orm.analysis.dao.impl;

import com.orm.analysis.dao.GenericJPADAO;
import com.orm.analysis.model.Address;
import com.orm.analysis.model.PerfAnalysis;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/10/13
 * Time: 11:55 AM
 * To change this template use File | Settings | File Templates.
 */
public class PerfAnalysisDAO extends GenericJPADAO<PerfAnalysis, Integer> {





    /**
        * List all the authors order by lastName,firstName ascendent
        *
        * @param page the page number
        * @param size the page size
        * @return a list of authors
        */
       public List<PerfAnalysis> list(int page, int size) {
           Query query = this.em.createQuery("select a  from PerfAnalysis a");
           query.setFirstResult((page - 1) * size);
           query.setMaxResults(size);
           return query.getResultList();
       }


       public PerfAnalysis getById(Integer id) {
               return this.emPerf.find(PerfAnalysis.class,id);
       }

       @Transactional
       @Override
       public void save(PerfAnalysis entity) {
            getEntityManagerPerf().persist(entity);
       }


    public List<Integer> findIdList() {
         Query query = this.emPerf.createQuery("select a.id from PerfAnalysis a ");
         return query.getResultList();
     }
}
